<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #div1{
            width: 200px;
            height: 200px;
            background: skyblue;
            position: absolute;

        }
    </style>
</head>
<body>
  <button id="btn" onclick="moveDiv()">点击移动</button>
  <div id="div1"></div>
  <script>
      var timer = null;
      var speed = 1;
      function moveDiv() {
          var oDiv = document.getElementById('div1');

          clearInterval(timer);
          timer = setInterval(function () {
              if (oDiv.offsetLeft >= 300){
                 clearInterval(timer);
              }
              else {
                  oDiv.style.left = oDiv.offsetLeft+speed+'px';
              }
          },30);
      }

  </script>
</body>
</html>